package user_local_ewallet

import (
	"context"
	"strconv"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/tool"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLocalEWalletInsertLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 添加
func NewUserLocalEWalletInsertLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLocalEWalletInsertLogic {
	return &UserLocalEWalletInsertLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserLocalEWalletInsertLogic) UserLocalEWalletInsert(req *types.UserLocalEwalletInsertRequest) (resp *types.UserLocalEwalletInsertResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserLocalEWalletsInsert(l.ctx, &rpc.UserLocalEwalletInsertRequest{
		UserId:           req.UserId,
		Type:             strconv.FormatInt(int64(req.Type), 10),
		Owner:            req.Owner,
		VisionLevel:      tool.ConvertInt32SliceToString(req.VisionLevel),
		Phone:            req.Phone,
		Code:             req.Code,
		RevenueMin:       req.RevenueMin,
		RevenueMax:       req.RevenueMax,
		FixedDailyLimit:  req.FixedDailyLimit,
		RemainDailyLimit: req.RemainDailyLimit,
		IncomeDailyLimit: req.IncomeDailyLimit,
		DailyLimit:       req.DailyLimit,
		Sort:             req.Sort,
		Remake:           req.Remark,
		IsVision:         req.IsVisible,
	})

	if err != nil {
		return &types.UserLocalEwalletInsertResponse{
			IsInsert: false,
		}, err
	}
	return &types.UserLocalEwalletInsertResponse{
		IsInsert: true,
	}, err
}
